import util from './../utils/util.js'
import config from './../utils/consts.js'
// var token = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyMDE4MTEwNjE3MDQzNDQxOTUwfG51bGx8ZGVidWd8ZGVidWd8ZGVidWd8ZGVidWd8MTU0MTU4MTc4MTY3OSIsImV4cCI6MTU0MTU4MTc4MX0.0Wi-PBxpvHcDfziCmV__3-HNOOU4llujinY_ddvKh9g'
class BaseApi {
  constructor() {
    // this.apiUrl = 'http://118.24.131.46:9002'
    //this.apiUrl = 'https://stlmapp.com/api/bjzyydx' //北京中医药大学
    this.apiUrl = 'https://stlmapp.com/api/myscfxy' //绵阳师范学院
  }
  http_get(url, data) {
    return new Promise((resove, reject) => {
      let obj = Object.assign(wx.getStorageSync('teamLogin') ? {
        token: util.getAdminToken()
      } : {
        token: util.getToken()
      }, {
        // let obj = Object.assign(wx.getStorageSync('teamLogin') ? { token: token } : {}, {
        // token: util.getToken(),
        // version: wx.getStorageSync('teamLogin') ? 'debug' : config.VERSION ,
        // client: wx.getStorageSync('teamLogin') ? 'debug' : config.CLIENT,
        // imei: wx.getStorageSync('teamLogin') ? 'debug' : config.IMEI
        version: config.VERSION,
        client: config.CLIENT,
        imei: config.IMEI
      }, data)
      wx.request({
        url: url,
        data: obj,
        method: 'GET',
        success: (res) => {
          if (res.data.code === -1) {
            if (res.data.err) {
              wx.showModal({
                title: '提示',
                content: res.data.err,
              })
            }
          }
          resove(res)
        },
        fail: (err) => {
          reject(err)
        }
      })
    })
  }
  http_post(url, data) {
    return new Promise((resove, reject) => {
      // let obj = Object.assign(wx.getStorageSync('teamLogin') ? { token: util.getAdminToken() } : {}, {
      // let obj = Object.assign(wx.getStorageSync('teamLogin') ? { token: token } : {}, {
      let obj = Object.assign(wx.getStorageSync('teamLogin') ? {
        token: util.getAdminToken()
      } : {
        token: util.getToken()
      }, {
        // version: wx.getStorageSync('teamLogin') ? 'debug' : config.VERSION,
        // client: wx.getStorageSync('teamLogin') ? 'debug' : config.CLIENT,
        // imei: wx.getStorageSync('teamLogin') ? 'debug' : config.IMEI
        version: config.VERSION,
        client: config.CLIENT,
        imei: config.IMEI
      }, data)
      wx.request({
        url: url,
        data: obj,
        header: {
          'content-type': 'application/x-www-form-urlencoded', // 默认值
        },
        method: 'POST',
        success: (res) => {
          if (res.data.errcode === -1) {
            if (res.data.err) {
              wx.showModal({
                title: '提示',
                content: res.data.err,
              })
            }
          }
          resove(res)
        },
        fail: (err) => {
          reject(err)
        }
      })
    })
  }
}
export default BaseApi